package com.jiatui.sharding.algorithm;

import java.util.Collection;

import io.shardingsphere.api.algorithm.sharding.PreciseShardingValue;
import io.shardingsphere.api.algorithm.sharding.standard.PreciseShardingAlgorithm;

/**
 * 一致性hash路由
 *
 */
public class ConsistentHashPreciseShardingAlgorithm implements PreciseShardingAlgorithm<Long>{

	@Override
	public String doSharding(Collection<String> availableTargetNames, PreciseShardingValue<Long> shardingValue) {
		ConsistentHashWithVirtualNode consistentHashWithVirtualNode = ConsistentHashWithVirtualNode.getInstance();
		consistentHashWithVirtualNode.setServers(availableTargetNames);
		return consistentHashWithVirtualNode.getServer(shardingValue.getValue());
	}

}
